Skip to content

refactor: code block & math block syntax highlighting#2873

Open
nperez0111 wants to merge 4 commits into
code-block-previewsfrom
syntax-highlighting
Open

refactor: code block & math block syntax highlighting#2873
nperez0111 wants to merge 4 commits into
code-block-previewsfrom
syntax-highlighting

Conversation

@nperez0111

Copy link
Copy Markdown
Contributor

Summary

The goal of this refactor was to use #2872 which allows for "sub extensions" (a blocknote extension within a blocknote extension) to be de-duped. And, leverage that to allow both the code-block & math block to operate with the syntax highlighting extension.

Now, the math block & code block declares how to highlight their contents & the syntax highlighting extension will pickup on them as being the nodes they should try to syntax highlight upon.

I've made the code block accept the syntax highlighter like it was accepting before. And, now the math block can accept a syntax highlighter (if for some reason you only care to configure the math block highlighting but not the code block one).

The trouble is how to handle both code block & the math extension wanting to configure the highlighter in different ways. Well, extensions can now only be registered once per key with #2872 so it will just silently drop one of the configurations and use one of the highlight instances to try to highlight both the math & code blocks.

I think this is a fine tradeoff for now, since you can really just leave the code block syntax highlighting on & get both code blocks & math blocks "for free". There is a larger question on how to do this in the more general case for extensions which depend on each other, but that is just a hard problem in programming in general.

Rationale

Changes

Impact

Testing

Screenshots/Video

Checklist

  • Code follows the project's coding standards.
  • Unit tests covering the new feature have been added.
  • All existing tests pass.
  • The documentation has been updated to reflect the new feature

Additional Notes

YousefED and others added 4 commits June 25, 2026 08:47
Logged-out buyers now go straight to Polar checkout instead of being
sent to /signup first.
De-duplication: when an extension with a given key is already registered,
skip registering another one with the same key (the first registration
wins). This lets an extension declare a dependency on another via
`blockNoteExtensions` without conflicting when that same extension is also
registered directly by the user.

Ordering: a sub-extension declared via `blockNoteExtensions` is a dependency
of the extension that declares it, so it now runs before its parent. The
dependency is recorded as the sub is resolved (before the de-duplication
check), so it holds even when multiple parents declare the same sub-extension
and when a parent has a higher base priority via `runsBefore`.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
… & math block can configure a highlighter for
@vercel

vercel Bot commented Jun 29, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
blocknote Ready Ready Preview Jun 29, 2026 1:40pm
blocknote-website Error Error Jun 29, 2026 1:40pm

Request Review

@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 13eee8ba-25e2-4f56-8e64-f9e7b44d5e89

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch syntax-highlighting

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@matthewlipski matthewlipski left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, I agree that trying to merge duplicate extensions is probably more effort than what we need atm and better to drop them.

Though I'm not a bit wary of keeping the highlighting option in meta when there is a specific extension for it. I think we should be careful when adding things to the custom block API that we don't end up with like a dozen unrelated config options that all live under meta. Probably fine in this case but yeah it's something we should be careful with. I guess an alternative would be to not bundle the syntax highlight extension with the code or math blocks, and make it completely standalone + configure highlighting there.

@nperez0111

Copy link
Copy Markdown
Contributor Author

My thinking there is that it is inflexible (and annoying) to have a shared dep have to be aware of the details of each block and it's special cases.

I would rather that the blocks could declare how they should be treated by an extension instead of the extension having to be aware of the block.

The reason is two fold:

  • if someone wants to add functionality to their block, (e.g. syntax highlighting) then they only have to touch their block, not some shared state
  • we also keep the implementation of the shared functionality hidden and unaware to the blocks an editor has or does not have. It keeps things simpler for the implementation.

A perfect example of this is the slash menu. Right now, we have the default blocks automatically injected into the shared slash menu array. When, if we did it in this way, we'd have each block declaring what sort of block it is and how to show itself in the slash menu. So, the slash menu would be simpler and including new things into the slash menu would be easier. Rather than having to modify the shared state somewhere else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants